random

 

random is a built in procedure to NetLogo that allows you to add randomness into your models. Imagine that each time you run the command random N, you are rolling a die with N number of sides.

The one thing you have to remember when using random is that the numbers you get out of range from 0 to N - 1, instead of 1 to N. For example, if you run random 3, you may get 0, 1, or 2. In the example below I add one to the result of random 6 to Account for this difference between NetLogo's random dice rolls and those of an actual six sided die.

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

Once you mastered the random primitive, don't stop there. Check out the resources below to improve your NetLogo skills.

 
Similar primitives:
random-float

generate a random real (non-whole) number within a specified range

Read more
random-normal

Randomly produces a number according to a normal distribution.

Read more
globals

defines variables that can be used throughout the whole model

Read more
turtles-own

Declare a variable that belongs to turtles.

Read more
 
Learn another primitive